<template>
  <div class="project-list">
    <el-card class="search-card" shadow="never">
      <template #header>
        <div class="card-header">
          <el-icon size="20" color="#2e7d32"><Search /></el-icon>
          <span>课题检索</span>
        </div>
      </template>
      <el-form inline :model="search" class="search-form">
        <el-form-item label="关键词">
          <el-input 
            v-model="search.keyword" 
            placeholder="标题/描述关键词" 
            clearable
            class="search-input"
          />
        </el-form-item>
        <el-form-item label="学科分类">
          <el-select 
            v-model="search.discipline" 
            clearable 
            placeholder="请选择学科"
            class="search-select"
          >
            <el-option v-for="d in disciplines" :key="d" :label="d" :value="d" />
          </el-select>
        </el-form-item>
        <el-form-item label="企业名称">
          <el-input 
            v-model="search.enterpriseName" 
            placeholder="企业名称" 
            clearable
            class="search-input"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleSearch">
            <el-icon><Search /></el-icon>
            查询
          </el-button>
          <el-button @click="handleReset">
            <el-icon><Refresh /></el-icon>
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </el-card>

    <div class="projects-grid">
      <el-row :gutter="24">
        <el-col :span="8" v-for="item in mock" :key="item.id">
          <el-card class="project-card" shadow="hover">
            <template #header>
              <div class="project-header">
                <div class="project-title">{{ item.title }}</div>
                <el-tag type="success" size="small">{{ item.enterpriseName }}</el-tag>
              </div>
            </template>
            <div class="project-content">
              <div class="project-tags">
                <el-tag 
                  v-for="t in item.researchDirection" 
                  :key="t" 
                  class="direction-tag"
                  size="small"
                >
                  {{ t }}
                </el-tag>
              </div>
              <p class="project-desc">{{ item.description }}</p>
              <div class="project-meta">
                <div class="meta-item">
                  <el-icon color="#2e7d32"><Calendar /></el-icon>
                  <span>截止：{{ item.deadline }}</span>
                </div>
                <div class="meta-item" v-if="item.budget">
                  <el-icon color="#4caf50"><Money /></el-icon>
                  <span>预算：{{ item.budget }}元</span>
                </div>
              </div>
              <div class="project-actions">
                <el-button type="primary" size="small" @click="viewDetail(item)">
                  <el-icon><View /></el-icon>
                  查看详情
                </el-button>
                <el-button type="success" size="small" @click="applyProject(item)">
                  <el-icon><Plus /></el-icon>
                  申请课题
                </el-button>
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>

    <div class="pagination-wrapper">
      <el-pagination 
        layout="total, sizes, prev, pager, next, jumper" 
        :total="30" 
        :page-sizes="[10, 20, 50]"
        background
      />
    </div>
  </div>
</template>

<script setup lang="ts">
import { mockProjects } from '@/services/mockData'
import { reactive } from 'vue'
import { Search, Refresh, Calendar, Money, View, Plus } from '@element-plus/icons-vue'

const disciplines = ['人工智能', '新材料', '网络安全', '计算机视觉', '电子工程', '生物医学', '环境科学']
const search = reactive({ keyword: '', discipline: '', enterpriseName: '' })
const mock = mockProjects

const handleSearch = () => {
  console.log('搜索参数:', search)
  // TODO: 实现搜索逻辑
}

const handleReset = () => {
  search.keyword = ''
  search.discipline = ''
  search.enterpriseName = ''
}

const viewDetail = (project: any) => {
  console.log('查看项目详情:', project)
  // TODO: 跳转到详情页
}

const applyProject = (project: any) => {
  console.log('申请项目:', project)
  // TODO: 跳转到申请页
}
</script>

<style scoped>
.project-list {
  max-width: 1200px;
  margin: 0 auto;
}

.search-card {
  margin-bottom: 32px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--primary-color);
}

.search-form {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
}

.search-input,
.search-select {
  width: 200px;
}

.projects-grid {
  margin-bottom: 32px;
}

.project-card {
  margin-bottom: 24px;
  border-radius: 12px;
  transition: all 0.3s ease;
  border: 1px solid var(--border-color);
}

.project-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(46, 125, 50, 0.15);
}

.project-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.project-title {
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.4;
  flex: 1;
}

.project-content {
  padding: 16px 0;
}

.project-tags {
  margin-bottom: 16px;
}

.direction-tag {
  margin-right: 8px;
  margin-bottom: 8px;
  background-color: rgba(46, 125, 50, 0.1);
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.project-desc {
  margin: 16px 0;
  color: var(--text-secondary);
  line-height: 1.6;
  min-height: 48px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.project-meta {
  margin-bottom: 20px;
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--text-secondary);
  font-size: 14px;
}

.project-actions {
  display: flex;
  gap: 12px;
}

.project-actions .el-button {
  flex: 1;
}

.pagination-wrapper {
  display: flex;
  justify-content: center;
  margin-top: 32px;
}
</style>


